package com.example.capturetheflag;

import com.example.capturetheflag.connection.HttpGetGamesRequest;
import com.example.capturetheflag.createGame.CreateGameActivity;
import android.os.Bundle;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;


public class MainMenuActivity extends Activity {
	
	private Dialog dialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_menu);
     	dialog = new Dialog(MainMenuActivity.this);    
        
        Button next = (Button) findViewById(R.id.createGameButton);
        next.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                Intent myIntent = new Intent(view.getContext(), CreateGameActivity.class);
                startActivityForResult(myIntent, 13);
            }

        });
        
        Button next2 = (Button) findViewById(R.id.joinGameButton);
        next2.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
            	HttpGetGamesRequest httpGetRequest = new HttpGetGamesRequest(getApplicationContext(),dialog);
            	httpGetRequest.execute("http://proinz.studentlive.pl/geoservice.svc/GetAllGames");
            	
                 dialog.setTitle("Please Wait for the connection");
                 dialog.show();
                 dialog.setCancelable(false);

            }

        });
        
        Button next3 = (Button) findViewById(R.id.clearServerButton);
        next3.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
            	com.example.capturetheflag.connection.HttpGetRequest httpGetRequest = new com.example.capturetheflag.connection.HttpGetRequest();
            	httpGetRequest.execute("http://proinz.studentlive.pl/GeoService.svc/ClearDataBase");
            	Toast.makeText(getBaseContext(), "All games deleted from server", Toast.LENGTH_SHORT).show();
            }
        });
    }

}
